package stringMVC.model;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import stringMVC.model.UserInfo;

import java.io.File;
import java.io.IOException;
import java.util.List;

@RestController
public class test {
    @RequestMapping("/hello")
    public String hello(){
        return "jjjj";
    }
    @RequestMapping("/demo1")
    public String demo1(String name){
        return name;
    }
    @RequestMapping("/r1")
    public String r1(@RequestBody UserInfo userInfo){
        return userInfo.toString();
    }
    @RequestMapping("/r2")
    public String r2(@RequestParam("list") List<String> list){
        return list.toString();
    }
    @RequestMapping("/r3")
    public String r3(@RequestParam("name") String username, String age){
        return username + " " + age;
    }
    @RequestMapping("/r4")
    public String r4(@RequestParam(value = "name",required = false) String username, String age){
        return username + " " + age;
    }

    @RequestMapping("/r5/{articleId}")
    public String r5(@PathVariable Integer articleId){
        return " " + articleId;
    }
    @RequestMapping("/r6")
    public String r6(@RequestPart MultipartFile file) throws IOException {
        String fileName = file.getOriginalFilename();
        file.transferTo(new File("E:/01/"+fileName));
        return fileName;
    }
    @RequestMapping("/r7/{name}/{age}")
    public String r7(@PathVariable("name") String username, @PathVariable Integer age){
        return username + " " + age;
    }
}
